/*
 * @(#)SingleURLResource.java $version 2012-3-2
 * 
 * Copyright 2011 RogueDevelopment Gruop. All rights Reserved.
 * ROGUEDEVELOPMENT PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nadostar.extensions.util;

import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;

/**
 * @author LEESUNG
 * 
 */
public class SingleURLResource implements Resource {
	private String name;
	private URL url;

	public SingleURLResource(String name, URL url) {
		this.name = name;
		this.url = url;
	}

	public String name() {
		return name;
	}

	public Collection<Resource> children() throws Exception {
		return Collections.emptyList();
	}

	public URL resource() throws Exception {
		return url;
	}

	public InputStream openStream() throws Exception {
		return url.openStream();
	}

	public boolean terminal() {
		return true;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this) {
			return true;
		}

		if (!(obj instanceof SingleURLResource)) {
			return false;
		}

		return this.name.equals(((SingleURLResource) obj).name)
				|| this.url.equals(((SingleURLResource) obj).url);
	}

	@Override
	public int hashCode() {
		return this.name.hashCode() + this.url.hashCode();
	}
}
